#include "Move.h"
#include "Engine.h"

using namespace std;

namespace Core
{

	//Move::Move() 
	//{
	//}

	Move::Move(Piece * piece, Square * to, ChAction action, int moveNum, Piece * pieceEaten)
	{
		if(piece == NULL || to == NULL)
			throw "Move::createMove: argument cannot be null";

		_next = NULL;
		_prev = NULL;
		_status = ChStatus::ChStatusNone;

		_piece = piece;
		_from = piece->square();
		_to = to;
		_action = action;
		_moveNum = moveNum;
		_eaten = pieceEaten;
	}

	Move::Move(const Move &move)
	{
		_piece = move.piece();
		_from = move.from();
		_to = move.to();
		_action = move.action();
		_moveNum = move.moveNum();
		_eaten = move.pieceEaten();

		_status = move.status();
		_next = move.nextMove();
		_prev = move.prevMove();
	}

	Move::~Move()
	{
	}

	//Move Move::createMove(Piece * piece, Square * dst)
	//{
	//	if(piece == NULL || dst == NULL)
	//		throw "Move::createMove: argument cannot be null";
	//	Piece * np = NULL;
	//	return Move(piece, piece->square(), dst, ChActionNone, -1, np);
	//}

	void Move::checkValidity(Move * mv)
	{
		if(mv == NULL)
			throw "Argument cannot be null";
		if(mv->piece() == NULL)
			throw "move.piece cannot be null";

		if(mv->to() == NULL)
			throw "move.to cannot be null";

		if(mv->from() == NULL)
			throw "move.from cannot be null";

		if(mv->moveNum() < 0)
			throw "move.moveNum cannot be less than 0";

	}

	string Move::toString() const
	{
		return to_string(_from->row()) + to_string(_from->column()) + to_string(_to->row()) + to_string(_to->column());
	}
}
